import Vue from "vue"
import Vuex from "vuex"

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: "", //init token
  },
  mutations: {
    setToken(state, token) {
      state.token = token
      localStorage.token = token
    },
    deleteToken(state) {
      state.token = ""
      localStorage.token = ""
    },
  },
  getters: {
    getToken(state) {
      if (!state.token) {
        state.token = localStorage.getItem("token")
      }
      return state.token
    },
  },
  actions: {},
})
